/**
 * 验证码等待时间
 * @type {number}
 */
sms_wait_time=60
/**
 * 验证码倒计时计数器
 * @type {number}
 */
sms_second_count=0
/**
 * 倒计时计数器
 * @type {null}
 */
overtime_clock = null
/**
 * 手机验证码倒计时器
 * @type {null}
 */
mobile_overtime_clock = null
/**
 * 手机验证码倒计时计数器
 * @type {number}
 */
mobile_sms_second_count=0

/**
 * 发送邮箱验证码
 * @param email
 * @constructor
 */
function SendEmailCode(e)
{
    if(sms_second_count > 0)
        return alert("请等待倒计时结束");
    else
        sms_second_count = sms_wait_time;
    //调接口发送验证码
    email = $("#email").val();
    if(email == '')
        return alert("请输入邮箱")
    post('/api/global/SendEmailCode', {
           'email': email
    }, function (response) {
        if(response.status==1)
        {
            //倒计时开始
            overtime_clock = window.setInterval(function ()
            {
                if(sms_second_count <= 0)
                {
                    clearInterval(overtime_clock);
                    $(e).html("获取验证码")
                    return;
                }
            $(e).html(sms_second_count >= 10 ? '请等待' + sms_second_count + '秒' : '请等待0' + sms_second_count + '秒')
            sms_second_count--;
            }, 1000)
        }else
            return alert("获取验证码失败,请刷新页面或稍后重试")
    },'json');
}

/**
 * 发送手机验证码
 * @param e
 * @constructor
 */
function SendMobileCode(e)
{
    if(mobile_sms_second_count > 0)
        return alert("请等待倒计时结束");
    else
        mobile_sms_second_count = sms_wait_time;
    //调接口发送验证码
    mobile = $("#monile").val();
    if(mobile == '')
        return alert("请输入手机号")
    post('/api/global/SendSmsCode', {
        'mobile': mobile
    }, function (response) {
        if(response.status==1)
        {
            //倒计时开始
            mobile_overtime_clock = window.setInterval(function ()
            {
                if(mobile_sms_second_count <= 0)
                {
                    clearInterval(mobile_overtime_clock);
                    $(e).html("获取验证码")
                    return;
                }
                $(e).html(mobile_sms_second_count >= 10 ? '请等待' + mobile_sms_second_count + '秒' : '请等待0' + mobile_sms_second_count + '秒')
                mobile_sms_second_count--;
            }, 1000)
        }else
            return alert("获取验证码失败,请刷新页面或稍后重试")
    },'json');
}

function sendFeedBack(e) {
   contact = $("#feedback_contact").val();
   context = $("#feedback_context").val();
   if(context == '')
       return alert("必须输入反馈内容")
    if(contact == '')
        return alert("必须输入联系方式")

    post('/api/global/SendFeeback', {
        'context': context,
        'contact': contact
    }, function (response) {
        if(response.status==1) {
            $(".box-opinion-mask").hide();
        }

        return alert(response.msg)
    },'json');
}

/**
 * 收藏商品
 * @param e
 * @param goods_id
 */
function collectGoods(e,goods_id)
{
    if(!$(e).hasClass("text-color3"))
    {
        post('/api/member/collectGoods', {
            'goods_id': goods_id
        }, function (response) {
            if(response.status==1) {
                $(e).addClass("text-color3")
                return;
            }

            return alert(response.msg)
        },'json');
    }else
    {
        post('/api/member/cancelCollectGoods', {
            'goods_id': goods_id
        }, function (response) {
            if(response.status==1) {
                $(e).removeClass("text-color3")
                return;
            }

            return alert(response.msg)
        },'json');
    }

}
